package com.weiyi.config;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebInitParam;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet(
		urlPatterns = {"/login1.do"},
		initParams = {
			@WebInitParam(name = "SUCCESS" , value = "success.view"),
			@WebInitParam(name = "ERROR" , value = "error.view")
		}
	)
public class Login extends HttpServlet{
	private  String SUCCESS_VIEW;
	private  String ERROR_VIEW;
	
	@Override
	public void init() throws ServletException {
		SUCCESS_VIEW = getInitParameter("SUCCESS");
		ERROR_VIEW = getInitParameter("ERROR");
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		resp.setContentType("text/html;charset=UTF-8");
		String username = req.getParameter("username");
		String password = req.getParameter("password");
		if("weiyi2020".equals(username) && "123456".equals(password)) {
			req.getRequestDispatcher(SUCCESS_VIEW).forward(req, resp);
		}else {
			req.getRequestDispatcher(ERROR_VIEW).forward(req, resp);
		}
	}
}
